<template>
  <div class="app-container">
    <el-form :inline="true" :model="queryParams" class="demo-form-inline">
      <el-form-item label="id" prop="id">
        <el-input v-model="queryParams.id" placeholder="id" />
      </el-form-item>
      <el-form-item label="昵称" prop="nickName">
        <el-input v-model="queryParams.nickName" placeholder="昵称" />
      </el-form-item>
      <el-form-item label="金额" prop="amount">
        <el-input v-model="queryParams.amount" placeholder="金额" />
      </el-form-item>
      <el-form-item label="开始日期" prop="startTime">
        <el-date-picker v-model="queryParams.startTime" type="datetime" placeholder="选择开始日期"
          value-format="yyyy-MM-dd HH:mm:ss" />
      </el-form-item>
      <el-form-item label="结束日期" prop="endTime">
        <el-date-picker v-model="queryParams.endTime" type="datetime" placeholder="选择结束日期"
          value-format="yyyy-MM-dd HH:mm:ss" />
      </el-form-item>
      <el-form-item label="充值单号">
        <el-input v-model="queryParams.orderNo" placeholder="充值单号" />
      </el-form-item>

      <!-- <el-form-item label="类型">
        <el-select v-model="queryParams.type" placeholder="请选择">
          <el-option
            v-for="item in typeOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="queryParams.status" placeholder="请选择">
          <el-option
            v-for="item in statusOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item> -->

      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="primary" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row>
      <el-table-column align="center" label="序号" width="95">
        <template slot-scope="scope">
          {{ scope.$index }}
        </template>
      </el-table-column>
      <el-table-column label="充值单号	" align="center" prop="orderNo" />
      <el-table-column label="充值金额" align="center" prop="amount">
        <template slot-scope="scope">
          {{ scope.row.amount }} <span style="margin-left: 8px;">{{ scope.row.type == 'rmb' ? 'rmb' : 'usdt' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="充值类型" align="center" prop="type">
        <template slot-scope="scope">
          {{ scope.row.type == 'rmb' ? 'rmb' : 'usdt' }}
        </template>
      </el-table-column>

      <el-table-column label="充值时间	" align="center" prop="createTime" />
      <el-table-column label="用户id	" align="center" prop="userId" />
      <el-table-column label="备注	" align="center" prop="remarks" />
      <el-table-column label="审核状态" align="center">
        <template slot-scope="scope">
          {{ setStateTxt(scope.row.status) }}
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="text" @click="handleShowInfo(scope.row)">审核</el-button>

        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination :current-page.sync="queryParams.pageNum" :page-sizes="[10, 20, 30, 40]"
        :page-size.sync="queryParams.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"
        @size-change="fetchData" @current-change="fetchData" />
    </div>
    <ShowInfo ref="showInfo" />
    <audio ref="audio" class="aud">
      <source src="@/assets/dingdingvoice.mp3">
    </audio>
  </div>
</template>

<script>
import { rechargeList } from '@/api/table'
import ShowInfo from './showInfo.vue'
export default {
  components: {
    ShowInfo

  },
  data() {
    return {
      list: null,
      listLoading: true,
      timer: null,
      total: 0,
      typeOptions: [
        { label: '虚拟货币', value: 'usdt' },
        { label: '人民币', value: 'rmb' }
      ],
      statusOptions: [
        { label: '申请中', value: 'applying' },
        { label: '审核通过', value: 'approved' },
        { label: '审核驳回', value: 'reject' }

      ],
      queryParams: {

        id: '',
        nickName: '',
        amount: '',
        startTime: '',
        endTime: '',
        orderNo: '',
        pageNum: 1,
        pageSize: 10,
        status: '',
        type: ''
      }
    }
  },
  created() {
    this.fetchData()
    clearInterval(this.timer)
    this.timer = setInterval(() => {
      this.fetchData()
    }, 10000)
  },
  beforeDestroy() {
    clearInterval(this.timer)
  },
  destroyed() {
    clearInterval(this.timer)
  },
  methods: {
    fetchData() {
      this.listLoading = true
      rechargeList(this.queryParams).then(response => {
        response.data.records.map(item => {
          if (item.status === 'applying') {
            this.play()
          }
        })
        this.list = response.data.records
        this.listLoading = false
        this.total = response.data.total
      })
    },
    play() {
      this.$nextTick(() => {
        console.log(this.$refs.audio)
        let music1 = new Audio()
        music1 = require('@/assets/dingdingvoice.mp3')
        this.$refs.audio.src = music1
        const audioDom = document.querySelector('.aud')
        audioDom && audioDom.click() // 模拟用户交互
        audioDom && audioDom.play() // 播放音频

        // this.$refs.audio.play()
      })
    },

    handleShowInfo(e) {
      this.$refs.showInfo.show(e)
    },
    setStateTxt(index) {
      let str = ''
      switch (index) {
        case 'applying':
          str = '申请中'
          break
        case 'approved':
          str = '审核通过'
          break
        case 'reject':
          str = '审核驳回'
          break
      }
      return str
    },
    onSubmit() {
      this.queryParams.page = 1
      this.fetchData()
    },
    reset() {
      this.queryParams = {

        hash: '',
        orderNo: '',
        pageNum: 1,
        pageSize: 10,
        status: '',
        type: ''
      }
      this.fetchData()
    },
    handleAdd() {
      this.$refs.add.show()
    },
    handleEdit(e) {
      this.$refs.add.edit(e)
    },
    handleDel(e) {
      this.$confirm('此操作将删除公告, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        communityDelete(e).then(res => {
          this.fetchData()
          this.$message({
            type: 'success',
            message: '成功!'
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        })
      })
    }
  }
}
</script>
